package hn.sigit.model.hnd.ladmshadow;

import hn.sigit.model.commons.IBAUnit;
import hn.sigit.model.commons.IParty;
import hn.sigit.model.commons.IRRR;
import hn.sigit.model.ladm.special.Rational;

import java.io.Serializable;
import java.util.HashSet;

import javax.persistence.*;

import org.hibernate.annotations.Columns;
import org.hibernate.annotations.Type;
@Entity
@org.hibernate.annotations.Proxy(lazy=false)
@Table(name="RRR", schema="ladmshadow")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorValue("RRR")
public abstract class RRR extends AssociationInfo implements IRRR, Serializable, Cloneable {
	private static final long serialVersionUID = 1L;
	
	private long rID;
	private Party party;
	private BAUnit baunit;
	private String description;
	private Rational share;
	private boolean shareCheck;
	private java.util.Date timeSpec;
	private java.util.Set<AdministrativeSource> adminSources = new java.util.HashSet<AdministrativeSource>();
	
	private long partyLadmId;
	
	
	public RRR() {
	}
	
	@Id
	@Column(name="ID", nullable=false)
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="shw_rrr_id_gen")
	@SequenceGenerator(name="shw_rrr_id_gen", sequenceName="shw_rrr_id_seq", allocationSize=1)
	public long getrID() {
		return rID;
	}
	protected void setrID(long value) {
		this.rID = value;
	}
	@Transient
	public long getRID() {
		return getrID();
	}
	
	@Column(name="Description", nullable=true, length=255)
	public String getDescription() {
		return description;
	}
	public void setDescription(String value) {
		this.description = value;
	}
	
	@Type(type = "hn.sigit.model.ladm.special.RationalUserType")
	@Columns(columns = {
			@Column(name = "share_numerator"),
			@Column(name = "share_denominator")
	})
	public hn.sigit.model.ladm.special.Rational getShare() {
		return share;
	}
	public void setShare(hn.sigit.model.ladm.special.Rational value) {
		this.share = value;
	}
	
	@Column(name="ShareCheck", nullable=false)
	public boolean getShareCheck() {
		return shareCheck;
	}
	public void setShareCheck(boolean value) {
		this.shareCheck = value;
	}
	
	@Column(name="TimeSpec", nullable=true)
	public java.util.Date getTimeSpec() {
		return timeSpec;
	}
	public void setTimeSpec(java.util.Date value) {
		this.timeSpec = value;
	}
	
	@ManyToOne(targetEntity=Party.class, fetch=FetchType.LAZY)
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.LOCK})
	@JoinColumns({ @JoinColumn(name="PartyID", referencedColumnName="ID") })
	@org.hibernate.annotations.LazyToOne(value=org.hibernate.annotations.LazyToOneOption.NO_PROXY)
	public Party getParty() {
		return party;
	}
	public void setParty(IParty value) {
		this.party = (Party)value;
	}
	
	@Override
	@ManyToOne(targetEntity=BAUnit.class, fetch=FetchType.LAZY)
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.LOCK})
	@JoinColumns({ @JoinColumn(name="BAUnitID", referencedColumnName="ID") })
	@org.hibernate.annotations.LazyToOne(value=org.hibernate.annotations.LazyToOneOption.NO_PROXY)
	public BAUnit getBaunit() {
		return baunit;
	}
	@Override
	public void setBaunit(IBAUnit value) {
		this.baunit = (BAUnit) value;
	}
	
	@ManyToMany(mappedBy="rrr", targetEntity=AdministrativeSource.class)
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK})
	@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.TRUE)
	public java.util.Set<AdministrativeSource> getAdminSources() {
		return adminSources;
	}
	public void setAdminSources(java.util.Set<AdministrativeSource> value) {
		this.adminSources = value;
	}
	
	@Transient
	public long getPartyLadmId() {
		return partyLadmId;
	}
	public void setPartyLadmId(long partyLadmId) {
		this.partyLadmId = partyLadmId;
	}
	
	public RRR clone() {
		RRR clonedRrr;
		try {
			clonedRrr = (RRR) super.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
			return null;
		}
		
		clonedRrr.setrID(0);
		
		clonedRrr.setParty(party);
		clonedRrr.setBaunit(baunit);
		clonedRrr.setDescription(description);
		clonedRrr.setShare(share);
		clonedRrr.setShareCheck(shareCheck);
		clonedRrr.setTimeSpec(timeSpec);
		clonedRrr.setAdminSources(new HashSet<AdministrativeSource>(adminSources));
		clonedRrr.setPartyLadmId(partyLadmId);

		return clonedRrr;
	}

	public String toString() {
		return super.toString();
	}
	
}
